A ligature is a glyph formed by two or more graphemes. Computer fonts with programming ligatures use ligatures to present lexemes formed of two or more symbols. There is disagreement over whether that is useful or harmful – harmful because the presentation masks the symbols required to form the lexeme in code.
Ian Tuomi’s Hasklig fonts add programming ligatures to Adobe’s Source Code Pro fonts, with Haskell’s lexemes in mind. For example, the code (in Consolas):
1 2 3 4 5 6 7 8 9 10 11 12 |
class Applicative m => Monad m where (>>=) :: forall a b. m a -> (a -> m b) -> m b (>>) :: forall a b. m a -> m b -> m b m >> k = m >>= \_ -> k return :: a -> m a return = pure fail :: String -> m a fail s = errorWithoutStackTrace s |
can be presented as (in Hasklig):
1 2 3 4 5 6 7 8 9 10 11 12 |
class Applicative m => Monad m where (>>=) :: forall a b. m a -> (a -> m b) -> m b (>>) :: forall a b. m a -> m b -> m b m >> k = m >>= \_ -> k return :: a -> m a return = pure fail :: String -> m a fail s = errorWithoutStackTrace s |
Microsoft ships another font with programming ligatures, Cascadia Code, with its Windows Terminal. However, that covers !=
(‘not equal to’ in C) and does not cover /=
(‘not equal to’ in Haskell).
Crayon Syntax Highlighter
Adding a font to the WordPress plugin Crayon Syntax Highlighter involves adding (1) a folder with the web font files and (2) an .css
file, to wp-content/uploads/crayon-syntax-highlighter/fonts/
. As an example of the .css
file:
1 2 3 4 5 6 7 8 9 10 |
@font-face { font-family: 'Hasklig'; src: url('hasklig/Hasklig-Regular.otf') format('opentype'); font-weight: normal; font-style: normal; } .crayon-font-hasklig * { font-family: 'Hasklig', 'Courier New', monospace !important; } |
This specifies an @font-face
rule for the web font and a rule with a descendant selector specifying the font-family
. The !important
keyword affects the order of the rule in the cascade.